package com.doctcloud.datacloud.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.doctcloud.common.core.annotation.Excel;
import com.doctcloud.common.core.annotation.NotZero;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;

import static com.doctcloud.common.core.utils.StringUtils.trim;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode(of = {"patientId","visitId","orderNo","orderSubNo"})
@TableName("orders")
public class OrdersEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Excel(name = "患者ID")
    @NotBlank(message = "患者ID不得为空")
    private String patientId;
    @Excel(name = "住院标识")
    @NotZero(message = "住院标识不得为零或NULL")
    private Integer visitId;
    @Excel(name = "医嘱号")
    @NotZero(message = "医嘱号不得为零或NULL")
    private Integer orderNo;
    @Excel(name = "医嘱子序号")
    @NotZero(message = "医嘱子序号不得为零或NULL")
    private Integer orderSubNo;
    @Excel(name = "长期标记" , readConverterExp = "0=临时,1=长期")
    private Integer repeatIndicator;
    @Excel(name = "医嘱类别")
    private String orderClass;
    @Excel(name = "医嘱正文")
    private String orderText;
    @Excel(name = "医嘱代码")
    private String orderCode;
    @Excel(name = "单次剂量")
    private Double dosage;
    @Excel(name = "单次剂量单位")
    private String dosageUnits;
    @Excel(name="启用时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date startDateTime;
    @Excel(name="停用时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date stopDateTime;
    @Excel(name = "频率描述")
    private String frequency;
    @Excel(name = "频率次数")
    private Integer freqCounter;
    @Excel(name = "频率间隔")
    private Integer freqInterval;
    @Excel(name = "频率间隔单位")
    private String freqIntervalUnit;
    @Excel(name = "执行时间详细描述")
    private String freqDetail;
    @Excel(name = "护士执行时间")
    private String performSchedule;
    @Excel(name = "开医嘱医生")
    private String doctor;
    @Excel(name = "停医嘱医生")
    private String stopDoctor;
    @Excel(name = "校对护士")
    private String nurse;
    @Excel(name = "录入时间")
    private Date enterDateTime;
    @Excel(name = "医嘱状态")
    private String orderStatus;
    @Excel(name="计价属性")
    private Integer billingAttr;
    @Excel(name = "最后执行时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date lastPerformDateTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Excel(name = "最后计价时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date lastAcctingDateTime;
    @Excel(name = "执行结果")
    private String performResult;
    @Excel(name = "开单科室代码")
    private String orderingDept;

    public void setOrderText(String orderText) {
        this.orderText = trim(orderText);
    }

    public void setFrequency(String frequency) {
        this.frequency = trim(frequency);
    }

    public void setFreqIntervalUnit(String freqIntervalUnit) {
        this.freqIntervalUnit = trim(freqIntervalUnit);
    }

    public void setFreqDetail(String freqDetail) {
        this.freqDetail = trim(freqDetail);
    }

    public void setPerformSchedule(String performSchedule) {
        this.performSchedule = trim(performSchedule);
    }

    public void setDoctor(String doctor) {
        this.doctor = trim(doctor);
    }

    public void setStopDoctor(String stopDoctor) {
        this.stopDoctor = trim(stopDoctor);
    }

    public void setNurse(String nurse) {
        this.nurse = trim(nurse);
    }

    public void setPerformResult(String performResult) {
        this.performResult = trim(performResult);
    }

    public void setOrderingDept(String orderingDept) {
        this.orderingDept = trim(orderingDept);
    }

    @Data
    public static class Key {
        private final String patientId;
        private final Integer visitId;
        private final Integer orderNo;
        private final Integer orderSubNo;

        public Key(String patientId, Integer visitId, Integer orderNo, Integer orderSubNo) {
            this.patientId = patientId;
            this.visitId = visitId;
            this.orderNo = orderNo;
            this.orderSubNo = orderSubNo;
        }
    }
}
